package com.iotek.bookstore.web.controlle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public abstract  class  CommonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/HTML;charset=utf-8");
        String doType=req.getParameter("doType");//接收用户请求操作的类型
        if(doType.equals("doInsert")){
            //操作类型为doInsert调用插入数据的方法
            doInsert(req,resp);
        }else if(doType.equals("doDelete")){
            //操作类型为doDelete调用删除数据的方法
            doDelete(req,resp);
        }else if(doType.equals("doUpdate")){
            //操作类型为doUpdate调用更新数据的方法
            doUpdate(req,resp);
        }else if(doType.equals("doQuery")){
            //操作类型为doQuery调用查询数据的方法
            doQuery(req,resp);
        }
    }
    /*
    * 做插入数据的抽象方法
    * */
    public abstract void doInsert(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;

    /*
    * 做删除数据的抽象方法
    * */
    public abstract void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;

    /*
    * 做更新数据的抽象方法
    * */
    public abstract void doUpdate(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;

    /*
    * 做查询数据的抽象方法
    * */
    public abstract void doQuery(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
}
